import os
import tools.globalvar as globalvar
import platform

basedir = os.path.abspath(os.path.dirname(__file__))


class Config:
    NOW_SYS=platform.system() or 'Windows'   #当前操作系统
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    FLASKY_MAIL_SUBJECT_PREFIX = '[Flasky]'
    FLASKY_MAIL_SENDER = '879651072@qq.com'
    FLASKY_ADMIN = os.environ.get('FLASKY_ADMIN')
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    SEND_FILE_MAX_AGE_DEFAULT=360000
    # ping相关
    PING_INTERVAL = os.environ.get('PING_INTERVAL') or 1
    PING_COUNTER = os.environ.get('PING_COUNTER') or -1
    PING_URL = os.environ.get('PING_URL') or "www.baidu.com"
    # 下载相关
    DOWNLOAD_MIN_FILE_SIZE = os.environ.get('DOWNLOAD_MIN_FILE_SIZE') or 1000000
    DOWNLOAD_UNDONE_DIR = os.environ.get('DOWNLOAD_UNDONE_DIR') or "download_undone"
    DATA_VER = os.environ.get('DATA_VER') or '0'
    # 服务器地址
    ERP_URL = os.environ.get('ERP_URL') or 'http://120.55.151.10:8080/'

    ROOT_PATH=os.getcwd() #程序运行根目录


    # 当前登录的店仓相关
    STORE_ID = globalvar.get_storebykey("CP_C_STORE_ID") or -1  # 店仓ID
    DISTRIB_CODE = os.environ.get('DISTRIB_CODE') or '01'  # 配销中编码
    DISTRIB_ID = os.environ.get('DISTRIB_ID') or '1240'  # 配销中ID
    DATAROOT_PATH = os.environ.get('DATAROOT_PATH') or ROOT_PATH+os.sep+'data'+os.sep+str(STORE_ID)  # 本地基础数据存放根目录
    POSBASEDB_NAME=os.environ.get('POSBASEDB_NAME') or 'posbase_'+DISTRIB_ID

    KEY_CUPCHECK = 'CUPCHECK'
    KEY_CUPREGIST = 'CUPREGIST'
    KEY_STORE = 'STORE'
    KEY_USER_REM = 'USER_REM'
    KEY_IS_USER_REM = 'IS_USER_REM'
    KEY_SALERS = 'SALERS'


    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):
    # DEBUG = True
    MAIL_SERVER = 'smtp.qq.com'
    MAIL_PORT = 587
    MAIL_USE_TLS = True
    MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
    MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URI') or \
                              'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')


class TestingConfig(Config):
    TESTING = False
    SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URI') or \
                              'sqlite:///' + os.path.join(basedir, 'data-test.sqlite')


class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI') or \
                              'sqlite:///' + os.path.join(basedir, 'data.sqlite')


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}